package com.zw.weiyi.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zw.weiyi.enety.Message;
import com.zw.weiyi.phonesms.R;
/**
 * 短信信息
 * @author Striver_zw
 *   Date  2014-12-13
 */
public class MessageAdapter extends BaseAdapter {

	private List<Message> mbList;
	private Context ctx;
	private LinearLayout layout_father;
	private LayoutInflater vi;
	private LinearLayout layout_child;
	private TextView tvDate;
	private TextView tvText;
	
	private Message mb;

	public MessageAdapter(Context context, List<Message> coll) {
		ctx = context;
		vi = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.mbList = coll;
	}

	public int getCount() {
		return mbList.size();
	}

	public Object getItem(int position) {
		return mbList.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		
		mb  = new  Message();
		mb = mbList.get(position);
		int itemLayout = mb.getLayoutID();
		layout_father = new LinearLayout(ctx);
		vi.inflate(itemLayout, layout_father, true);

		layout_father.setBackgroundColor(Color.TRANSPARENT);
		layout_child = (LinearLayout) layout_father.findViewById(R.id.layout_bj);

		tvText = (TextView) layout_father.findViewById(R.id.messagedetail_row_text);
		tvText.setText(mb.getText());

		tvDate = (TextView) layout_father.findViewById(R.id.messagedetail_row_date);
		tvDate.setText(mb.getDate());

		//设置事件
		addListener(tvText, tvDate, layout_child, mb);

		return layout_father;
	}

	public void addListener(final TextView tvText, final TextView tvDate,
			LinearLayout layout_bj, final Message mb) {

		layout_bj.setOnTouchListener(new OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				switch (event.getAction()) {

				case MotionEvent.ACTION_DOWN:

				case MotionEvent.ACTION_MOVE:
					tvText.setTextColor(0xffffffff);
					break;

				default:
					tvText.setTextColor(Color.BLACK);
					break;
				}
				return false;
			}
		});
	}
}
